package com.school.appleforgetbackend.service;

import com.school.appleforgetbackend.jpa.entity.AccountInfoEntity;
import com.school.appleforgetbackend.jpa.repository.AccountInfoRepository;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import javax.xml.crypto.Data;
import java.util.Date;
import java.util.List;

/**
 * @author Emil
 */
@Service
public class AccountService {
    private final AccountInfoRepository accountInfoRepository;

    public AccountService(AccountInfoRepository accountInfoRepository) {
        this.accountInfoRepository = accountInfoRepository;
    }

    @Transactional  // 开启事务
    public AccountInfoEntity createAccountInfo(String phoneNumber, String password) {
        AccountInfoEntity accountInfoEntity = new AccountInfoEntity();
        accountInfoEntity.setPhoneNumber(phoneNumber);
        accountInfoEntity.setPassword(password);
        accountInfoEntity.setCreateTime(new Date());
        return accountInfoRepository.save(accountInfoEntity);
    }

    public List<AccountInfoEntity> getAccountInfoEntityList() {
        return accountInfoRepository.findAll();
    }
}
